//
// Created by hunan on 25-4-4.
//

#ifndef FLV_PARSER_H
#define FLV_PARSER_H

#include "flv_message.h"

#include <cstdint>

class FlvParser
{
public:
    enum ParserFlvStatus
    {
        INI,
        NEED_DATA,
        FINISH,
        BAD,
    };
    enum FlvProtocolStatus
    {
        PARSER_INIT,
        PARSER_FLV_HEADER,
        PARSER_FLV_TAG,
        PARSER_FLV_TAG_FINISH,
        PARSER_BAD,
    };
public:
    FlvParser();
    int                          ParseFlvMessage(const uint8_t * data, int data_length, int & use_length);
    int                          FlvProtocolStatus() const;
    struct FlvMessage::FlvHeader GetFlvHeader();
    struct FlvMessage::FlvTag *  GetMetaData();
    struct FlvMessage::FlvTag *  GetFlvTag();
    void                         RemoveFlvTag();
    int ParseFlvHeader(const uint8_t * data, int data_length, int & use_length);
    int ParseFlvTag(const uint8_t * data, int data_length, int & use_length);
    static int ParseFlvTagHeader(const uint8_t * data, int data_length, int & use_length, FlvMessage::FlvTag & tag);
    static int ParseFlvTagData(const uint8_t * data, int data_length, int & use_length, FlvMessage::FlvTag & tag);

private:
    int        m_parser_status;
    FlvMessage m_flv_message;
};

#endif // FLV_PARSER_H
